<?php

class objFile{
	public $name;
	
	public function __construct($fileName){
		$this->name = $fileName;
	}
	
	public function ReadInstance(){
		$filePath = getcwd().DIRECTORY_SEPARATOR."obj".DIRECTORY_SEPARATOR.$this->name;
		if(file_exists($filePath)){
			$objData = file_get_contents($filePath);
			$obj = unserialize($objData);
			return $obj;
		}
		return NULL;
	}
	
	public function SaveInstance($obj){
		$filePath = getcwd().DIRECTORY_SEPARATOR."obj".DIRECTORY_SEPARATOR.$this->name;
		if(is_writable($filePath)){
			$fp = fopen($filePath, "w");
			$objData = serialize($obj);
			fwrite($fp, $objData);
			fclose($fp);
		}
	}
}
?>